﻿using XLib.Base;
using XNode.SubSystem.OptionSystem;
using System.Windows.Forms;
namespace XNode.SubSystem.ProjectSystem
{
    /// <summary>
    /// 文件工具
    /// </summary>
    public class FileTool
    {
        private FileTool()
        {
            _projectFilter.TypeList.Add(new TypeInfo("节点项目", "xnode"));
            _projectFilter.TypeList.Add(new TypeInfo("节点项目", "json"));
        }
        public static FileTool Instance { get; } = new FileTool();

        /// <summary>
        /// 打开读取项目对话框
        /// </summary>
        public string OpenReadProjectDialog()
        {
            var dialog = new OpenFileDialog()
            {
                InitialDirectory = OptionManager.Instance.ProjectPath,
                Filter = _projectFilter.ToString(),
            };
            return dialog.ShowDialog() == DialogResult.OK ? dialog.FileName : "";
        }

        /// <summary>
        /// 打开保存项目对话框
        /// </summary>
        public string OpenSaveProjectDialog(string fileName)
        {
            var dialog = new SaveFileDialog()
            {
                InitialDirectory = OptionManager.Instance.ProjectPath,
                FileName = $"{fileName}.xnode",
                Filter = _projectFilter.ToString(),
            };
            var result = dialog.ShowDialog();
            if (result == DialogResult.OK)
                return dialog.FileName;
            else
            {
                return "";
            }
        }

        private readonly FileFilter _projectFilter = new FileFilter();
    }
}